// components/gameOver/gameOver.js
let utils = require('../../utils/util.js');
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    hideGameOver: {
      type: Boolean,
      value: true
    },
    userInfoA: {
      type: Object,
      value: {}
    },
    userInfoB: {
      type: Object,
      value: {}
    },
    thisScore: {
      type: Number,
      value: 0
    },
    fractionA: {
      type: Number,
      value: 0
    },
    fractionB: {
      type: Number,
      value: 0
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    win: 'winA',
    hidePop: true,
    rankName: '群众演员',
    sum: 0,
    max: 19,
    upText: '恭喜升级',
    tipText: '恭喜升级'    
  },
  ready: function() {
    const {
      userInfoA,
      userInfoB,
      fractionA,
      fractionB,
      thisScore
    } = this.properties;
    let win = 'winA';
    if (fractionB > fractionA) {
      win = 'winB';
    }

    //获取答题前用户积分情况
    let {
      score
    } = userInfoA;

    //获取答题前段位情况
    let {
      max,
      rankName
    } = utils.getRank(score);
    //计算总得分
    let sum =  score + thisScore;

    app.globalData.userInfo.score = sum;
    if (sum > max) {
      this.setData({
        hidePop: false,
        win: win,
        sum: sum,
        rankName: utils.getRank(sum)['rankName'],
        max: utils.getRank(sum)['max']
      });
    } else if(max > 99) {
      this.setData({
        win: win,
        sum: sum,
        rankName: utils.getRank(sum)['rankName'],
        max: '∞'
      });
    } else {
      this.setData({
        win: win,
        sum: sum,
        rankName: rankName,
        max: max
      });
    }

    
  },
  /**
   * 组件的方法列表
   */
  methods: {
    backIndex: function () {
      wx.navigateTo({
        url: '../../pages/index/index'
      })
    },
    closePop: function () {
      this.setData({
        hidePop: true
      });
    },
  }
})
